/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vistas;

import entidades.Deposito;
import entidades.IngresoMaterial;
import entidades.LoteIngresoMaterial;
import entidades.Material;
import entidades.ProveedorRepuesto;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import reportes.GenReportes;
import rn.MaterialRN;
import rn.RepuestoRN;

/**
 *
 * @author Pablo
 */
public class FormIngresoMateriales extends javax.swing.JFrame {

    static Material material_selected;
    IngresoMaterial ingresoMaterial;
    DefaultTableModel modelo_tabla;
    List<IngresoMaterial> ls_ingresos;

    public FormIngresoMateriales(Material rep) {
        initComponents();
        ls_ingresos = new ArrayList();
        iniciarModeloTabla();
        this.setLocationRelativeTo(null);
        this.llenarCombos();
        if (rep != null) {
            llenarCampos(rep);
        }
        tf_codigo.addKeyListener(new buscarMaterial());
        bt_confirmar.addKeyListener(new AccionConfirmar());
        habilitarPanel2(false);
        bt_cerrar_ingreso.setEnabled(false);

        tf_cantidad_ingresada.addKeyListener(new CambiarCampo());
        tf_monto.addKeyListener(new CambiarCampo());
        tf_nro_factura.addKeyListener(new CambiarCampo());
        combo_proveedores.addKeyListener(new CambiarCampo());
        combo_depositos.addKeyListener(new CambiarCampo());
        bt_agregar.addKeyListener(new AgregarMaterial());

        this.setResizable(false);        
        this.setVisible(true);
    }

    public static void llenarCampos(Material r) {
        material_selected = r;
        tf_codigo.setText(r.getCodigo());
        tf_descripcion.setText(r.getDescripcion());
        tf_descripcion.setBackground(new Color(204, 255, 255));
        tf_subtipo.setText(r.getSubTipoMaterial().getDescripcion());
        tf_subtipo.setBackground(new Color(204, 255, 255));
        tf_codigo_barras.setText(r.getCodigo_barras());
        tf_codigo_barras.setBackground(new Color(204, 255, 255));
        tf_tipo_material.setText(r.getSubTipoMaterial().getTipoMaterial().getDescripcion());
        tf_tipo_material.setBackground(new Color(204, 255, 255));
        tf_stock.setText(Utils.redondearNumero(r.getStock(), 2));
        tf_stock.setBackground(new Color(204, 255, 255));
        tf_precio_unitario.setText("" + r.getPrecio_unitario());
        tf_precio_unitario.setBackground(new Color(204, 255, 255));
    }

    private void llenarCombos() {
        List<ProveedorRepuesto> todosProveedorMaterials = RepuestoRN.getTodosProveedorRepuesto();
        List<Deposito> todosDeposito = RepuestoRN.getTodosDeposito();

        llenarCombo(combo_proveedores, todosProveedorMaterials);
        llenarCombo(combo_depositos, todosDeposito);
    }

    public void llenarCombo(JComboBox combo, List lista) {
        for (Object c : lista) {
            combo.addItem(c);
        }
    }

    private void habilitarPanel2(boolean b) {
        panel2.setEnabled(b);
        tf_cantidad_ingresada.setEnabled(b);
        tf_nro_factura.setEnabled(b);
        tf_detalle.setEnabled(b);
        combo_calendario.setEnabled(b);
        combo_depositos.setEnabled(b);
        combo_proveedores.setEnabled(b);
        tf_monto.setEnabled(b);
        bt_agregar.setEnabled(b);
        bt_quitar_de_la_tabla.setEnabled(b);
    }

    public class CambiarCampo extends KeyAdapter {

        public void keyPressed(KeyEvent ke) {
            if (ke.getKeyCode() == KeyEvent.VK_ENTER && ke.getSource() == tf_cantidad_ingresada) {
                tf_monto.requestFocus();
                tf_monto.setBackground(new Color(204, 255, 255));
                tf_cantidad_ingresada.setBackground(Color.WHITE);
                tf_monto.setText(""+Double.parseDouble(getMultiplicarDecimal("" + material_selected.getPrecio_unitario(), tf_cantidad_ingresada.getText())));
            }            
            if (ke.getKeyCode() == KeyEvent.VK_ENTER && ke.getSource() == tf_monto) {
                tf_monto.setBackground(Color.WHITE);
                tf_nro_factura.setBackground(new Color(204, 255, 255));
                tf_nro_factura.requestFocus();
            }
            if (ke.getKeyCode() == KeyEvent.VK_ENTER && ke.getSource() == tf_nro_factura) {
                tf_nro_factura.setBackground(Color.WHITE);
                combo_depositos.requestFocus();
            }
            if (ke.getKeyCode() == KeyEvent.VK_ENTER && ke.getSource() == combo_depositos) {
                combo_proveedores.requestFocus();
            }
            if (ke.getKeyCode() == KeyEvent.VK_ENTER && ke.getSource() == combo_proveedores) {
                bt_agregar.requestFocus();
            }
        }
    }

    private class AgregarMaterial extends KeyAdapter {

        public void keyPressed(KeyEvent ke) {
            if (agregarMaterial()) {
                habilitarPanel2(false);
                limpiarCampos();
                tf_codigo.setEditable(true);
                tf_codigo.requestFocus();
                bt_confirmar.setEnabled(false);
                bt_selecionar.setEnabled(true);
                tf_codigo.setBackground(new Color(204, 255, 255));
            }
        }
    }

    public class buscarMaterial extends KeyAdapter {

        public void keyPressed(KeyEvent e) {
            accion(e);
        }

        public void accion(KeyEvent e) {
            tf_codigo.setBackground(Color.WHITE);
            tf_info.setText(null);
            if (e.getSource() == tf_codigo) {
                if (e.VK_ENTER == e.getKeyCode()) {
                    String id_text = tf_codigo.getText();
                    if (verificarValor(id_text)) {
                        Material v = MaterialRN.getMaterialXId(new Long(id_text));
                        if (v != null) {
                            llenarCampos(v);
                            bt_confirmar.setEnabled(true);
                            bt_confirmar.requestFocus();
                        } else {
                            tf_info.setText("No se encuentra material");
                            limpiarCampos();
                        }
                    } else {
                        tf_codigo.setBackground(Color.PINK);
                        tf_info.setText("el código ingresado es invalido o no se encuentra vehículo");
                        limpiarCampos();
                    }
                }
            }
        }
    }

    public class AccionConfirmar extends KeyAdapter {

        public void keyPressed(KeyEvent e) {
            action(e);
        }

        private void action(KeyEvent e) {
            if (e.VK_S == e.getKeyCode() || e.VK_ENTER == e.getKeyCode()) {
                confirmar();
                tf_cantidad_ingresada.setBackground(new Color(204, 255, 255));
            }
            if (e.VK_N == e.getKeyCode()) {
                tf_codigo.requestFocus();
            }
        }
    }

    private void confirmar() {
        tf_codigo.setEditable(false);
        bt_selecionar.setEnabled(false);
        bt_confirmar.setEnabled(false);
        habilitarPanel2(true);
        tf_cantidad_ingresada.requestFocus();
    }

    private boolean verificarValor(String text) {
        return (text.matches("[+]?\\d*(\\\\d+)?") && text.equals("") == false);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tf_codigo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tf_descripcion = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tf_stock = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tf_codigo_barras = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tf_tipo_material = new javax.swing.JTextField();
        tf_subtipo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        bt_selecionar = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        tf_precio_unitario = new javax.swing.JTextField();
        bt_confirmar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        panel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        tf_nro_factura = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        combo_proveedores = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        combo_depositos = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        combo_calendario = new org.freixas.jcalendar.JCalendarCombo();
        jLabel11 = new javax.swing.JLabel();
        tf_detalle = new javax.swing.JTextField();
        bt_agregar = new javax.swing.JButton();
        tf_cantidad_ingresada = new javax.swing.JTextField();
        Monto = new javax.swing.JLabel();
        tf_monto = new javax.swing.JTextField();
        bt_cancelar = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        bt_quitar_de_la_tabla = new javax.swing.JButton();
        bt_cerrar_ingreso = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        tf_info = new javax.swing.JLabel();
        bt_cancelar1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Material"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Código:");

        tf_codigo.setBackground(new java.awt.Color(204, 255, 255));
        tf_codigo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_codigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_codigoActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Descripcion:");

        tf_descripcion.setEditable(false);
        tf_descripcion.setBackground(new java.awt.Color(255, 255, 255));
        tf_descripcion.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_descripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_descripcionActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Stock:");

        tf_stock.setEditable(false);
        tf_stock.setBackground(new java.awt.Color(255, 255, 255));
        tf_stock.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_stock.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_stockActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Código de barra:");

        tf_codigo_barras.setEditable(false);
        tf_codigo_barras.setBackground(new java.awt.Color(255, 255, 255));
        tf_codigo_barras.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_codigo_barras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_codigo_barrasActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Material:");

        tf_tipo_material.setEditable(false);
        tf_tipo_material.setBackground(new java.awt.Color(255, 255, 255));
        tf_tipo_material.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_tipo_material.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_tipo_materialActionPerformed(evt);
            }
        });

        tf_subtipo.setEditable(false);
        tf_subtipo.setBackground(new java.awt.Color(255, 255, 255));
        tf_subtipo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_subtipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_subtipoActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Sub Tipo:");

        bt_selecionar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_selecionar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arrow_left.png"))); // NOI18N
        bt_selecionar.setText("BUSCAR MATERIAL");
        bt_selecionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_selecionarActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel15.setText("Precio Unitario:");

        tf_precio_unitario.setEditable(false);
        tf_precio_unitario.setBackground(new java.awt.Color(255, 255, 255));
        tf_precio_unitario.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tf_precio_unitario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_precio_unitarioActionPerformed(evt);
            }
        });

        bt_confirmar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_confirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/help.png"))); // NOI18N
        bt_confirmar.setText("Confirmar? SI 'S'  - NO 'N'");
        bt_confirmar.setEnabled(false);
        bt_confirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_confirmarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tf_codigo_barras)
                            .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(tf_tipo_material, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(42, 42, 42)
                                .addComponent(jLabel7))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tf_subtipo, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tf_stock, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(bt_selecionar)
                        .addGap(27, 27, 27)
                        .addComponent(bt_confirmar, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel15)
                        .addGap(10, 10, 10)
                        .addComponent(tf_precio_unitario, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(tf_stock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tf_codigo_barras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_tipo_material, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(tf_subtipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_precio_unitario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(bt_selecionar)
                        .addComponent(bt_confirmar))))
        );

        jPanel2.setBackground(new java.awt.Color(0, 0, 153));

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("INGRESO DE MATERIALES");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        panel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Cantidad, depósito, proveedor"));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setText("Cantidad:");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Factura:");

        tf_nro_factura.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("Proveedor:");

        combo_proveedores.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Deposito destino:");

        combo_depositos.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel14.setText("Fecha:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Observación:");

        tf_detalle.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        bt_agregar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_agregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        bt_agregar.setText("AGREGAR");
        bt_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarActionPerformed(evt);
            }
        });

        tf_cantidad_ingresada.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        Monto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        Monto.setText("Monto:");

        tf_monto.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
        panel2.setLayout(panel2Layout);
        panel2Layout.setHorizontalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tf_detalle, javax.swing.GroupLayout.PREFERRED_SIZE, 555, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panel2Layout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
                                .addComponent(Monto)
                                .addGap(8, 8, 8))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                            .addGroup(panel2Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(8, 8, 8)))
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tf_cantidad_ingresada)
                            .addComponent(tf_monto, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tf_nro_factura, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(36, 36, 36)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel12)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(combo_depositos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(combo_proveedores, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(combo_calendario, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(bt_agregar)
                .addContainerGap())
        );
        panel2Layout.setVerticalGroup(
            panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(tf_cantidad_ingresada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Monto)
                            .addComponent(tf_monto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tf_nro_factura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10)))
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(combo_depositos, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(combo_proveedores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(combo_calendario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(tf_detalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_agregar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        bt_cancelar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        bt_cancelar.setText("CANCELAR");
        bt_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelarActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Lista de ingresos"));

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tabla);

        bt_quitar_de_la_tabla.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        bt_quitar_de_la_tabla.setText("Quitar");
        bt_quitar_de_la_tabla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_quitar_de_la_tablaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 703, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_quitar_de_la_tabla)
                .addContainerGap(49, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(bt_quitar_de_la_tabla))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bt_cerrar_ingreso.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_cerrar_ingreso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/accept.png"))); // NOI18N
        bt_cerrar_ingreso.setText("CERRAR INGRESO");
        bt_cerrar_ingreso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cerrar_ingresoActionPerformed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel16.setText("Info:");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tf_info, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(tf_info, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        bt_cancelar1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        bt_cancelar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/cancel.png"))); // NOI18N
        bt_cancelar1.setText("SALIR");
        bt_cancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(bt_cerrar_ingreso)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bt_cancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_cancelar1)))
                .addGap(25, 25, 25))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_cerrar_ingreso, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_cancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tf_codigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_codigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_codigoActionPerformed

    private void tf_descripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_descripcionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_descripcionActionPerformed

    private void tf_stockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_stockActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_stockActionPerformed

    private void tf_codigo_barrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_codigo_barrasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_codigo_barrasActionPerformed

    private void tf_tipo_materialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_tipo_materialActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_tipo_materialActionPerformed

    private void tf_subtipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_subtipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_subtipoActionPerformed

    private void bt_selecionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_selecionarActionPerformed
        new SeleccionarMaterial(1);

    }//GEN-LAST:event_bt_selecionarActionPerformed


    private void bt_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelarActionPerformed
        int op = JOptionPane.showConfirmDialog(null, "¿Desea cancelar TODO el ingreso?");
        if (op == 0) {
            bt_agregar.setEnabled(false);
            bt_quitar_de_la_tabla.setEnabled(false);
            bt_confirmar.setEnabled(false);
            bt_selecionar.setEnabled(true);
            tf_codigo.setEditable(true);
            limpiarCampos();
            ls_ingresos = new ArrayList<>();
            modelo_tabla = new DefaultTableModel();
            tabla.setModel(modelo_tabla);
            iniciarModeloTabla();
            tf_codigo.requestFocus();
        }
    }//GEN-LAST:event_bt_cancelarActionPerformed

    private void bt_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarActionPerformed
        agregarMaterial();
        tf_codigo.setBackground(new Color(204, 255, 255));
    }//GEN-LAST:event_bt_agregarActionPerformed

    private boolean agregarMaterial() {
        blanquearCampos();
        if (material_selected != null) {
            if (veficarCamposRequeridos()) {
                if (verificarValorDecimal("" + tf_cantidad_ingresada.getText())) {
                    if (Double.parseDouble(tf_cantidad_ingresada.getText()) > 0) {
                        agregarALista();
                        limpiarCampos();
                        bt_cerrar_ingreso.setEnabled(true);
                        material_selected = null;
                        return true;
                    } else {
                        JOptionPane.showMessageDialog(null, "El valor ingresado debe ser mayor a cero");
                        tf_cantidad_ingresada.setBackground(Color.PINK);
                        tf_cantidad_ingresada.requestFocus();
                        return false;
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "El valor ingresado no es valido");
                    tf_cantidad_ingresada.setBackground(Color.PINK);
                    tf_cantidad_ingresada.requestFocus();
                    return false;
                }
            } else {
                JOptionPane.showMessageDialog(null, "Hay campos requeridos");
                return false;
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe selecionar un material");
            tf_codigo.requestFocus();
            return false;
        }
    }

    private boolean verificarValorDecimal(String text) {
        return (text.matches("[+]?\\d*(\\.\\d+)?") && text.equals("") == false);
    }


    private void bt_cerrar_ingresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cerrar_ingresoActionPerformed
        if (!ls_ingresos.isEmpty()) {
            LoteIngresoMaterial lote = new LoteIngresoMaterial();
            lote.setFecha(combo_calendario.getDate());
            lote.setResponsable(Principal.usuario);
            MaterialRN.newLoteIngresoMaterial(lote);

            for (IngresoMaterial ing : ls_ingresos) {
                ing.setLoteIngresoMaterial(lote);
                MaterialRN.newIngresoMaterial(ing);
                Material material = ing.getMaterial();
                material.setStock(material.getStock() + ing.getCantidad());
                MaterialRN.modificar(material);
            }

            ls_ingresos = new ArrayList<>();
            modelo_tabla = new DefaultTableModel();
            tabla.setModel(modelo_tabla);
            iniciarModeloTabla();
            limpiarCampos();
            habilitarPanel2(false);
            bt_cerrar_ingreso.setEnabled(false);
            JOptionPane.showMessageDialog(null, "Datos guardados!!!");
            Long ultimoLoteIngresado = MaterialRN.getUltimoLoteDeIngresoDeMateriales();
            new GenReportes().repIngresoRepuestosXIdLote(ultimoLoteIngresado);
        } else {
            JOptionPane.showMessageDialog(null, "No hay datos para guardar");
        }
    }//GEN-LAST:event_bt_cerrar_ingresoActionPerformed

    private void bt_quitar_de_la_tablaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_quitar_de_la_tablaActionPerformed
        if (tabla.getSelectedRow() != -1) {
            int selectedRow = tabla.getSelectedRow();
            ls_ingresos.remove(selectedRow);
            modelo_tabla.removeRow(selectedRow);
            tabla.setModel(modelo_tabla);
        }
    }//GEN-LAST:event_bt_quitar_de_la_tablaActionPerformed

    private void tf_precio_unitarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_precio_unitarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_precio_unitarioActionPerformed

    private void bt_confirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_confirmarActionPerformed
        confirmar();
    }//GEN-LAST:event_bt_confirmarActionPerformed

    private void bt_cancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelar1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_bt_cancelar1ActionPerformed

    private void agregarALista() {
        IngresoMaterial ingresoMaterial = new IngresoMaterial();
        ingresoMaterial.setMaterial(material_selected);
        ingresoMaterial.setDeposito((Deposito) combo_depositos.getSelectedItem());
        ingresoMaterial.setNro_factura(tf_nro_factura.getText());
        ingresoMaterial.setPrecio_total(Double.parseDouble(tf_monto.getText()));
        ingresoMaterial.setProveedor((ProveedorRepuesto) combo_proveedores.getSelectedItem());
        ingresoMaterial.setCantidad(Double.parseDouble(tf_cantidad_ingresada.getText()));
        ingresoMaterial.setPrecio_unitario(material_selected.getPrecio_unitario());
        //ingresoMaterial.setPrecio_total(Double.parseDouble(getMultiplicarDecimal("" + material_selected.getPrecio_unitario(), tf_cantidad_ingresada.getText())));
        ls_ingresos.add(ingresoMaterial);
        agegarATabla(ingresoMaterial);
    }

    private void agegarATabla(IngresoMaterial ing) {
        Object fila[] = new Object[]{
            ing.getMaterial().getDescripcion(), ing.getMaterial().getPrecio_unitario(), ing.getCantidad(), tf_monto.getText(), ing.getProveedor()
        };
        modelo_tabla.addRow(fila);
        tabla.setModel(modelo_tabla);
    }

    private void iniciarModeloTabla() {
        Object datos[][] = {};
        String[] columnNames = {"Descripcion", "Precio unitario", "Cantidad", "Precio total", "Proveedor"};
        modelo_tabla = new DefaultTableModel(datos, columnNames);
    }

    private boolean esEnteroPositivo(String text) {
        return (text.matches("[+]?\\d*(\\\\d+)?") && text.equals("") == false);
    }

    private boolean veficarCamposRequeridos() {
        if (tf_nro_factura.getText().isEmpty() || tf_nro_factura.getText().startsWith(" ")) {
            tf_nro_factura.setBackground(Color.PINK);
            tf_nro_factura.requestFocus();
            return false;
        }
        if (tf_monto.getText().isEmpty() || tf_monto.getText().startsWith(" ")) {
            tf_monto.setBackground(Color.PINK);
            tf_monto.requestFocus();
            return false;
        }
        return true;
    }

    public void blanquearCampos() {
        tf_nro_factura.setBackground(Color.WHITE);
        tf_cantidad_ingresada.setBackground(Color.WHITE);
        tf_monto.setBackground(Color.WHITE);
    }

    private void limpiarCampos() {
        tf_cantidad_ingresada.setText(null);
        tf_monto.setText(null);
        tf_subtipo.setText(null);
        tf_subtipo.setBackground(Color.WHITE);
        tf_descripcion.setText(null);
        tf_descripcion.setBackground(Color.WHITE);
        tf_detalle.setText(null);
        tf_detalle.setBackground(Color.WHITE);
        tf_codigo_barras.setText(null);
        tf_codigo_barras.setBackground(Color.WHITE);
        tf_tipo_material.setText(null);
        tf_tipo_material.setBackground(Color.WHITE);
        tf_nro_factura.setText(null);
        tf_nro_factura.setBackground(Color.WHITE);
        tf_codigo.setText(null);
        tf_codigo.setBackground(Color.WHITE);
        tf_stock.setText(null);
        tf_stock.setBackground(Color.WHITE);
        tf_precio_unitario.setText(null);
        tf_precio_unitario.setBackground(Color.WHITE);
    }

    //private double getMultiplicarDecimal(double n1, double m){
    private String getMultiplicarDecimal(String n1, String n2) {
        BigDecimal suma = new BigDecimal(n1).multiply(new BigDecimal(n2));
        suma = suma.setScale(2, BigDecimal.ROUND_HALF_UP);
        return suma.toString();
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Monto;
    private javax.swing.JButton bt_agregar;
    private javax.swing.JButton bt_cancelar;
    private javax.swing.JButton bt_cancelar1;
    private javax.swing.JButton bt_cerrar_ingreso;
    public static javax.swing.JButton bt_confirmar;
    private javax.swing.JButton bt_quitar_de_la_tabla;
    private javax.swing.JButton bt_selecionar;
    private org.freixas.jcalendar.JCalendarCombo combo_calendario;
    private javax.swing.JComboBox combo_depositos;
    private javax.swing.JComboBox combo_proveedores;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel panel2;
    private javax.swing.JTable tabla;
    private javax.swing.JTextField tf_cantidad_ingresada;
    public static javax.swing.JTextField tf_codigo;
    public static javax.swing.JTextField tf_codigo_barras;
    public static javax.swing.JTextField tf_descripcion;
    private javax.swing.JTextField tf_detalle;
    private javax.swing.JLabel tf_info;
    private javax.swing.JTextField tf_monto;
    private javax.swing.JTextField tf_nro_factura;
    public static javax.swing.JTextField tf_precio_unitario;
    public static javax.swing.JTextField tf_stock;
    public static javax.swing.JTextField tf_subtipo;
    public static javax.swing.JTextField tf_tipo_material;
    // End of variables declaration//GEN-END:variables

}
